package com.ludomancy.starwave;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;

import com.ludomancy.gamelib.Sound;
import com.ludomancy.gamelib.Utils;
import com.ludomancy.gamelib.Widget;

public class MothershipWidget extends Widget
{
	private Player owner;
	public BigExplosionAnimation deathAnimation;
	
	public MothershipWidget(Widget parent, Rectangle area, Player owner)
	{
		super(parent, area);
		this.owner = owner;
	}
	
	public void startDeathAnimation()
	{
		Image icon = Settings.getMothershipIcon(owner.direction);
		Point pos = Utils.getCenterInRect(new Point(icon.getWidth(null), icon.getHeight(null)), getClientRect());
		deathAnimation = new BigExplosionAnimation(pos.x , pos.y );
		deathAnimation.start();
		new Sound("blow.wav").play();
	}


	public void paint(Graphics g)
	{
		Graphics2D g2 = (Graphics2D) g;
		
		if(owner == Game.game.me)
		{
			Image icon = Settings.getMothershipIcon(owner.direction);
			Point pos = Utils.getCenterInRect(new Point(icon.getWidth(null), icon.getHeight(null)), getClientRect());
			g2.drawImage(icon, pos.x, pos.y, null);
			if(deathAnimation != null && !deathAnimation.isOver())
			{
				deathAnimation.update();
				deathAnimation.paint(g);
				if(deathAnimation.isOver())
				{
					Game.game.endPhase();
				}
			}
		}
	}
}
